//package com.example.socket_client_demo;
//
//import android.app.Service;
//import android.content.ComponentName;
//import android.content.Intent;
//import android.content.pm.PackageManager;
//import android.content.pm.ServiceInfo;
//import android.os.Binder;
//import android.os.IBinder;
//import android.os.RemoteException;
//import android.widget.Toast;
//import com.uwantsoft.goeasy.client.goeasyclient.GoEasy;
//
///**
// * @author Chuanbao
// */
//public class GoEasyService1 extends Service {
//
//    private GoEasy goEasy;
//    private GoEasyBinder1 goEasyBinder1 = new GoEasyBinder1();
//
//    private GoEasyDemo gservice2 = new GoEasyDemo.Stub() {
//        @Override
//        public void startService() throws RemoteException {
//            Intent service2 = new Intent(getBaseContext(),GoEasyService2.class);
//            getBaseContext().startService(service2);
//        }
//
//        @Override
//        public void stopService() throws RemoteException {
//            Intent service2 = new Intent(getBaseContext(),GoEasyService2.class);
//            getBaseContext().stopService(service2);
//        }
//    };
//    private String Process_Name = "com.example.socket_client_demo.goeasy2";
//
//    @Override
//    public void onCreate() {
//        Toast.makeText(GoEasyService1.this, "Service1 onCreate...", Toast.LENGTH_SHORT)
//                .show();
////        ComponentName cn=new ComponentName(getApplication(), GoEasyService1.class);
////        ServiceInfo info= null;
////        try {
////            info = this.getPackageManager()
////                    .getServiceInfo(cn, PackageManager.GET_META_DATA);
////            String appkey=info.metaData.getString("appkey");
////            Toast.makeText(GoEasyService1.this, "GoEasy appkey:"+appkey, Toast.LENGTH_SHORT)
////                    .show();
////            if(StringUtils.isEmpty(appkey)){
////                throw new IllegalStateException("App key is required.");
////            }
////            String appkey = ServiceUtils.getAppKey(getApplicationContext());
////            goEasy = new GoEasy(appkey,getApplication());
////        } catch (PackageManager.NameNotFoundException e) {
////            throw new IllegalStateException("App key is required.");
////        }
//        String appkey = ServiceUtils.getAppKey(getApplicationContext());
//        Toast.makeText(GoEasyService1.this, "GoEasy appkey:"+appkey, Toast.LENGTH_SHORT)
//                .show();
//        goEasy = new GoEasy(appkey,getApplication());
//        keepService2();
//    }
//
//    @Override
//    public int onStartCommand(Intent intent, int flags, int startId) {
//        Toast.makeText(GoEasyService1.this, "Service1 onStartCommand...", Toast.LENGTH_SHORT)
//                .show();
//        return super.onStartCommand(intent,flags,startId);
//    }
//
//    @Override
//    public void onTrimMemory(int level) {
//        Toast.makeText(getBaseContext(), "Service1 onTrimMemory..." + level, Toast.LENGTH_SHORT)
//                .show();
//
//        keepService2();//保持Service2一直运行
//    }
//
//    private void keepService2(){
//        boolean isRunService2 = ServiceUtils.isProessRunning(GoEasyService1.this, Process_Name);
//        if (!isRunService2) {
//            try {
//                Toast.makeText(getBaseContext(), "重新启动 Service2", Toast.LENGTH_SHORT).show();
//                gservice2.startService();
//            } catch (RemoteException e) {
//                e.printStackTrace();
//            }
//        }
//    }
//
//
//    @Override
//    public IBinder onBind(Intent intent) {
//        return goEasyBinder1;
//    }
//
//    public class GoEasyBinder1 extends Binder{
//        public GoEasyService1 getGoEasyService1(){
//            return GoEasyService1.this;
//        }
//        public GoEasy goEasy(){
//            return GoEasyService1.this.goEasy;
//        }
//    }
//
//}
